package com.zfh.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @title:
 * @author: fhzheng
 * @date: 3/15/2021 17:00
 * @description:
 */

@WebServlet("/json")
public class JSONServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setContentType("text/html;charset=utf-8");

        JSONObject obj = new JSONObject();
        JSONArray array = new JSONArray();

        for(int x=0;x<10;x++){
            JSONObject temp = new JSONObject();
            temp.put("id",x+1000);
            temp.put("title","地点是："+x+"号基地");
            array.add(temp);
        }
        obj.put("code",1);
        obj.put("status","OK");
        obj.put("allAddress",array);
        response.getWriter().println(obj);
    }
}
